<script type="text/javascript">
    $(document).ready(function() {
        $('#mode').change(function() {
            var types = ["admin", "manager"];
            if ($.inArray($(this).val(), types) >= 0) {
                $('#roles').load('<?php echo base_url(ADMIN_FOLDER . '/users/getroles/') . '/'; ?>' + $(this).val() +
                        '<?php if (isset($user)) echo '/' . $user->id ?>')
            } else {
                $('#roles').html(' ');
            }
        })
        $('#mode').change()
    })
</script>
<form class="form-horizontal" action="<?= current_url() ?>" method="post" id="form-validate" >
            <div id="validation" class="row-fluid">
                <div class="span12">
                    <div class="box corner-all">
                        <div class="box-header grd-white color-silver-dark corner-top">
                            <div class="header-control">
                                <a data-box="collapse"><i class="icofont-caret-up"></i></a>
                                
                            </div>
                            <span><?= lang('label_menu_link_users'); ?></span>
                        </div>
                        <div class="box-body">
                            
                                <fieldset>
                                    <legend><?= (isset($user)) ? lang('label_edit') . ' ' . $user->username : lang('label_add') . " " . lang('label_by_mode_user'); ?></legend>

                                    <div class="control-group">
                                        <label class="control-label" for="fname"><?= lang('label_fname') ?></label>
                                        <div class="controls">
                                            <input type="text" class="grd-white" name="fname" placeholder="<?= lang('label_fname') ?>" id="fname"  value="<?= (form_val('fname')) ? form_val('fname') : $user->first_name ?>" />
                                        </div>
                                    </div>
                                    
                                    <div class="control-group">
                                        <label class="control-label" for="mname"><?= lang('label_mname') ?></label>
                                        <div class="controls">
                                            <input type="text" class="grd-white" name="mname" placeholder="<?= lang('label_mname') ?>" id="mname"  value="<?= (form_val('mname')) ? form_val('mname') : $user->middle_name ?>" />
                                        </div>
                                    </div>
                                    
                                    <div class="control-group">
                                        <label class="control-label" for="username"><?= lang('label_username') ?></label>
                                        <div class="controls">
                                            <input type="text" class="grd-white" data-validate="{required: true, messages:{required:'Please enter field required'}}" name="username" placeholder="<?= lang('label_username') ?>" id="username"  value="<?= (isset($user->username)) ? $user->username : set_value('username') ?>" />
                                        </div>
                                    </div>
                                    
                                    <div class="control-group">
                                        <label class="control-label" for="username"><?= lang('label_username') ?></label>
                                        <div class="controls">
                                            <input type="text" class="grd-white" data-validate="{required: true, messages:{required:'Please enter field required'}}" name="username" placeholder="<?= lang('label_username') ?>" id="username"  value="<?= (isset($user->username)) ? $user->username : set_value('username') ?>" />
                                        </div>
                                    </div>
                                    
                                    
                                    <div class="control-group">
                                        <label class="control-label" for="username"><?= lang('label_username') ?></label>
                                        <div class="controls">
                                            <input type="text" class="grd-white" data-validate="{required: true, messages:{required:'Please enter field required'}}" name="username" placeholder="<?= lang('label_username') ?>" id="username"  value="<?= (isset($user->username)) ? $user->username : set_value('username') ?>" />
                                        </div>
                                    </div>
                                    
                                    
                                    <div class="control-group">
                                        <label class="control-label" for="username"><?= lang('label_username') ?></label>
                                        <div class="controls">
                                            <input type="text" class="grd-white" data-validate="{required: true, messages:{required:'Please enter field required'}}" name="username" placeholder="<?= lang('label_username') ?>" id="username"  value="<?= (isset($user->username)) ? $user->username : set_value('username') ?>" />
                                        </div>
                                    </div>
                                    
                                    <div class="control-group">
                                        <label class="control-label" for="username"><?= lang('label_username') ?></label>
                                        <div class="controls">
                                            <input type="text" class="grd-white" data-validate="{required: true, messages:{required:'Please enter field required'}}" name="username" placeholder="<?= lang('label_username') ?>" id="username"  value="<?= (isset($user->username)) ? $user->username : set_value('username') ?>" />
                                        </div>
                                    </div>
                                    
                                    <div class="control-group">
                                        <label class="control-label" for="username"><?= lang('label_username') ?></label>
                                        <div class="controls">
                                            <input type="text" class="grd-white" data-validate="{required: true, messages:{required:'Please enter field required'}}" name="username" placeholder="<?= lang('label_username') ?>" id="username"  value="<?= (isset($user->username)) ? $user->username : set_value('username') ?>" />
                                        </div>
                                    </div>
                                    
                                    <div class="control-group">
                                        <label class="control-label" for="username"><?= lang('label_username') ?></label>
                                        <div class="controls">
                                            <input type="text" class="grd-white" data-validate="{required: true, messages:{required:'Please enter field required'}}" name="username" placeholder="<?= lang('label_username') ?>" id="username"  value="<?= (isset($user->username)) ? $user->username : set_value('username') ?>" />
                                        </div>
                                    </div>
                                    
                                    <div class="control-group">
                                        <label class="control-label" for="username"><?= lang('label_username') ?></label>
                                        <div class="controls">
                                            <input type="text" class="grd-white" data-validate="{required: true, messages:{required:'Please enter field required'}}" name="username" placeholder="<?= lang('label_username') ?>" id="username"  value="<?= (isset($user->username)) ? $user->username : set_value('username') ?>" />
                                        </div>
                                    </div>
                                    
                                    <div class="control-group">
                                        <label class="control-label" for="username"><?= lang('label_username') ?></label>
                                        <div class="controls">
                                            <input type="text" class="grd-white" data-validate="{required: true, messages:{required:'Please enter field required'}}" name="username" placeholder="<?= lang('label_username') ?>" id="username"  value="<?= (isset($user->username)) ? $user->username : set_value('username') ?>" />
                                        </div>
                                    </div>
                                    
                                    <div class="control-group">
                                        <label class="control-label" for="username"><?= lang('label_username') ?></label>
                                        <div class="controls">
                                            <input type="text" class="grd-white" data-validate="{required: true, messages:{required:'Please enter field required'}}" name="username" placeholder="<?= lang('label_username') ?>" id="username"  value="<?= (isset($user->username)) ? $user->username : set_value('username') ?>" />
                                        </div>
                                    </div>
                                    
                                    <div class="control-group">
                                        <label class="control-label" for="username"><?= lang('label_username') ?></label>
                                        <div class="controls">
                                            <input type="text" class="grd-white" data-validate="{required: true, messages:{required:'Please enter field required'}}" name="username" placeholder="<?= lang('label_username') ?>" id="username"  value="<?= (isset($user->username)) ? $user->username : set_value('username') ?>" />
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label class="control-label" for="username"><?= lang('label_username') ?></label>
                                        <div class="controls">
                                            <input type="text" class="grd-white" data-validate="{required: true, messages:{required:'Please enter field required'}}" name="username" placeholder="<?= lang('label_username') ?>" id="username"  value="<?= (isset($user->username)) ? $user->username : set_value('username') ?>" />
                                        </div>
                                    </div>

                                    <div class="control-group">
                                        <label class="control-label" for="email"><?= lang('label_email') ?></label>
                                        <div class="controls">
                                            <input type="email" class="grd-white" data-validate="{required: true, minlength: 2, messages:{required:'Please enter field min length', minlength:'Please enter at least 2 characters.'}}" value="<?= (isset($user->email)) ? $user->email : set_value('email') ?>" name="email" placeholder="<?= lang('label_email') ?>" id="email" />
                                        </div>
                                    </div>

                                    <div class="control-group">
                                        <label class="control-label" for="mode"><?= lang('label_by_mode') ?></label>
                                        <div class="controls">
                                            <select id="mode" name="mode" data-form="select2" style="width:200px" data-placeholder="<?= lang('label_by_mode') ?>">
                                                <option value="user" <?php if (isset($user)) if ($user->mode == 'user') echo 'selected';  ?> ><?= lang('label_by_mode_user') ?></option>
                                                <option value="admin" <?php if (isset($user)) if ($user->mode == 'admin') echo 'selected';  ?> ><?= lang('label_by_mode_admin') ?></option>
                                                <option value="manager" <?php if (isset($user)) if ($user->mode == 'manager') echo 'selected';  ?> ><?= lang('label_by_mode_manager') ?></option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="control-group">
                                        <label class="control-label" for="password"><?= lang('label_password') ?></label>
                                        <div class="controls">
                                            <input type="password" class="grd-white" data-validate="{required: true, messages:{required:'Please enter field password'}}" placeholder="<?= lang('label_password') ?>" value="<?= set_value('password') ?>" name="password" id="password" />
                                        </div>
                                    </div>
                                    <div class="control-group">
                                        <label class="control-label" for="confpassword"><?= lang('label_confpassword') ?></label>
                                        <div class="controls">
                                            <input type="password" class="grd-white" data-validate="{required: true, equalTo: '#password', messages:{required:'Please enter field confirm password', equalTo: 'confirmation password does not match the password'}}" placeholder="<?= lang('label_confpassword') ?>" value="<?= set_value('confpassword') ?>" name="confpassword" id="confpassword" />
                                        </div>
                                    </div>

                                    <?php if (isset($user)) if (in_array($user->mode, array('user'))) { ?>
                                            <div class="control-group">
                                                <label class="control-label" for="subscrib"></label>
                                                <div class="controls">
                                                    <label class="checkbox">
                                                        <input type="checkbox" data-form="uniform" name="subscrib" id="inlineCheckbox1" placeholder="<?= lang('label_subscrib') ?>" <?php
                                                        if (isset($user)) {
                                                            if ($user->subscrib == 'YES')
                                                                echo 'checked';
                                                        }
                                                        else
                                                            echo 'checked';
                                                        ?> type="checkbox" /><?= lang('label_subscrib') ?>
                                                    </label>

                                                </div>
                                            </div>
                                        <?php } ?>

                                    <div class="control-group">
                                        <label class="control-label" for="confirm_email"></label>
                                        <div class="controls">
                                            <label class="checkbox">
                                                <input type="checkbox" data-form="uniform" name="confirm_email" id="inlineCheckbox1" placeholder="<?= lang('label_confirm_email') ?>" <?php
                                                if (isset($user)) {
                                                    if ($user->confirm_email == 'YES')
                                                        echo 'checked';
                                                }
                                                else
                                                    echo 'checked';
                                                ?> type="checkbox" /><?= lang('label_confirm_email') ?>
                                            </label>

                                        </div>
                                    </div>

                                    <div class="form-actions">
                                        <button type="submit" class="btn btn-primary"><?= (isset($user)) ? lang('label_edit') : lang('label_add'); ?></button>
                                        <button type="button" class="btn">Cancel</button>
                                    </div>
                                </fieldset>
                                
                           
                        </div>
                    </div>
                </div>
            </div>
    
    <div id="roles"></div>
 </form>

